package flyweight;

import java.util.Random;

/**
 * @Author: Ma JiBin
 * @Email: 1423553596@qq.com
 * @Date: 2018/9/10 10:46
 * @Description: 享元模式（Flyweight Pattern）
 */
public class Main {
    private static final String[] COLORS =
            {"Red", "Green", "Blue", "White", "Black"};

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            Circle circle =
                    (Circle) ShapeFactory.getCircle(getRandomColor());
            circle.setX(getRandomX());
            circle.setY(getRandomY());
            circle.setRadius(100);
            circle.draw();
        }

    }

    /**
     * 随机获取颜色方法
     * @return color
     */
    private static String getRandomColor() {
        return COLORS[(int) (Math.random() * COLORS.length)];
    }

    /**
     * 随机生成0-100X轴坐标方法
     * @return x
     */
    private static int getRandomX() {
        return (int) (Math.random() * 100);
    }

    /**
     * 随机生成0-100Y轴坐标方法
     * @return y
     */
    private static int getRandomY() {
        return new Random().nextInt(100);
    }
}
